#include #include #include using namespace std; void main(){ ofstream fout; ifstream fin; fout.open("tstname.txt"); fout << "Kenneth L Moore " << endl; fout.close(); fin.open("tstname.txt"); //fin >> name; will only get Kenneth // this is the messy but necessary way // to get a line of text including blanks char *buff = new char[80]; fin.getline(buff,80); string name(buff); delete [] buff;// do not forget: or memory leak cout << "Name from file " << name << endl; fin.close(); fout.open("filero.txt"); for(int i = 0; i < 10; i++) fout << i << endl; fout.close(); fout.open("filero.txt", ios::app); for(int i = 10; i < 20; i++){ fout << i << endl; } fout.close(); fin.open("filero.txt"); int fx; while(!fin.eof()){ fin >> fx; if(!fin.eof()) cout << fx << endl; } fin.close(); // invalid file name fin.open("fileor.txt", ios::app); if(fin.fail()){ cout << " file open failed " << endl; } else fin.close(); }